<template>
  <div>
    <div id="park_num"></div>
    <div class="footer">
      <div class="ratio">
        <div class="ratio_text">
          <div>同比</div>
          <div>
            <img class="arrow" src="../../img/topArrow.png" />
            <span class="arrow_text">10%</span>
          </div>
        </div>
        <div class="img_box"></div>
      </div>
      <div class="count">
        <div class="count_text">
          <div>未转化商机</div>
          <div style="font-size: 20px; font-weight: bold; color: #ffffff">
            {{ props.numData.oppoType2 }}
            <span
              style="
                font-size: 16px;
                color: rgba(255, 255, 255, 0.6);
                margin-left: 20px;
              "
              >个</span
            >
          </div>
        </div>
        <div class="count_img"></div>

        <div class="count_text">
          <div>已转化商机</div>
          <div style="font-size: 20px; font-weight: bold; color: #ffffff">
            {{ props.numData.oppoType1 }}

            <span
              style="
                font-size: 16px;
                color: rgba(255, 255, 255, 0.6);
                margin-left: 20px;
              "
              >个</span
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { onMounted, watchEffect } from "vue";
const props = defineProps({
  data: {
    type: Array,
    default: () => {
      return [];
    },
  },
  numData: {
    type: Object,
    default: () => {
      return {};
    },
  },
});
const initChart = () => {
  var chartDom = document.getElementById("park_num");
  var myChart = echarts.init(chartDom);
  var option;

  option = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
      },
    },
    textStyle: {
      color: "rgba(255, 255, 255, 0.6)",
      fontFamily: "Source Han Sans",
      fontSize: "18px",
      fontWeight: "normal",
    },

    legend: {
      right: "5%",

      textStyle: {
        color: "rgba(255, 255, 255)",
      },
    },
    grid: {
      left: "3%",
      right: "4%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        data: props.data.map((item) => item.name),
        axisLabel: {
          //interval设置成 0 强制显示所有标签
          interval: 0,
        },
      },
    ],
    yAxis: [
      {
        type: "value",
        splitLine: {
          //网格线
          show: false,
        },
      },
    ],
    series: [
      {
        name: "新签约客户",
        type: "bar",
        emphasis: {
          focus: "series",
        },
        data: props.data.map((item) => item.new),
        itemStyle: {
          // 使用方法一的写法
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "#6ED29B" },

            { offset: 1, color: "#0E7BC8" },
          ]),
        },
      },
      {
        name: "续签客户",
        type: "bar",
        stack: "Ad",
        emphasis: {
          focus: "series",
        },

        data: props.data.map((item) => item.renewal),
        itemStyle: {
          // 使用方法一的写法
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "#BBA96E" },

            { offset: 1, color: "#977B2F " },
          ]),
        },
      },
    ],
  };

  option && myChart.setOption(option);
};

onMounted(() => {});
watchEffect(() => {
  if (props.data.length > 0) {
    initChart();
  }
});
</script>

<style scoped>
#park_num {
  width: 100%;
  height: 450px;
}

.footer {
  width: 100%;
  height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ratio {
  position: relative;
  width: 373px;
  height: 52px;
  opacity: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ratio_text {
  width: 40%;
  height: 100%;
  z-index: 99;

  display: flex;
  align-items: center;
  color: rgba(255, 255, 255, 1);
  font-size: 14px;
  font-weight: bold;
  justify-content: space-between;
}
.ratio_text div {
  width: 50%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.arrow {
  width: 16px;
  height: 16px;
}
.arrow_text {
  font-size: 20px;
  font-weight: bold;
  line-height: 19.6px;
  letter-spacing: 0em;

  color: #ff5b5b;
}
.count {
  position: relative;

  width: 80%;
  height: 52px;
  opacity: 1;
  background: linear-gradient(
    90deg,
    rgba(13, 31, 38, 0.4) 3%,
    rgba(23, 51, 62, 0.4) 47%,
    rgba(13, 31, 38, 0.4) 99%
  );

  box-shadow: inset 0px 0px 4px 0px #5493d8;
  display: flex;
  justify-content: center;
  align-items: center;
}
.count_text {
  width: 30%;
  height: 100%;
  display: flex;
  align-items: center;
  z-index: 99;
  justify-content: space-evenly;
  font-style: 14px;
  color: rgba(255, 255, 255, 0.6);
}
.count_img {
  margin-top: -10px;
  width: 66px;
  height: 66px;
  background: url("../../img/mark.png") no-repeat;
  background-size: cover;
}
.img_box {
  z-index: 1;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: url("../../img/ratio.png") no-repeat;
  background-size: cover;
}
</style>
